home *** CD-ROM | disk | FTP | other *** search
- Path: solon.com!not-for-mail
- From: seebs@solutions.solon.com (Peter Seebach)
- Newsgroups: comp.lang.c
- Subject: Re: malloc question
- Date: 11 Mar 1996 10:36:19 -0600
- Organization: Usenet Fact Police (Undercover)
- Message-ID: <4i1kq3$2m0@solutions.solon.com>
- References: <4htonk$350@news.hklink.net> <314318AF.30F@iperbole.bologna.it> <4hvaj4$laj@solutions.solon.com> <AD69AACE9668D78B0@mcdiala09.it.luc.edu>
- NNTP-Posting-Host: solutions.solon.com
-
- In article <AD69AACE9668D78B0@mcdiala09.it.luc.edu>,
- Verne Arase <VArase@varase.it.luc.edu> wrote:
- >Well, in the general case it _could_ hide an error.
-
- >In this specific case, however, it _never_ hides an error. If malloc is
- >used in its standard context, we are simply coercing a slab of memory
- >aligned to the most stringent boundaries into a pointer of the desired
- >type.
-
- Which does *nothing*, because void pointers always convert to the desired type
- silently and automatically.
-
- Further, it *did* hide an error in the specific case; <stdlib.h> was not
- included, and there was no prototype in scope.
-
- >Provided the associated header is included (and the memory model doesn't
- >change through some devious, manual manipulation), you are _always_ safe in
- >coercing a malloc allocated block of memory into the desired pointer type.
-
- And you are _always_ redundant doing so, unless you're passing to a varaidic
- function or one with no prototype in scope.
-
- >This is one reason I stopped participating in C conferences; there's always
- >some language lawyer who'll tell a novice that a cast is an evil (even if
- >it has to do with casting a char * to an unsigned char * for use in a file
- >name). What they normally fail to tell you is that any code much beyond the
- >sophistication of "Hello World" practically requires casts to produce
- >workable code.
-
- Bullshit. I have written vast applications which, through careful use of void
- pointers, need no casts at all. 90% of casts in code I see posted to
- comp.lang.c are useless; many of them are wrong.
-
- >IMO, making a char a signed quantity (along with the infamous misplacement
- >of the boolean and operator's priority) have made more C programmer's lives
- >miserable than any other construct in any other language (that I've
- >encountered).
-
- char is not a signed quantity. char is a quantity which may be signed or
- unsigned.
-
- It's a question of usage. An unspecified short, int, or long is *always*
- signed, so it is clearly desireable for char to be signed. EOF is negative,
- and the getc family all return unsigned char or EOF, so it is clearly
- desireable for char to be unsigned.
-
- >Sure there are constructs that'll get you in trouble. But let us not forget
- >that C is the original "gun, bullet, foot" language, and requires care in
- >its use and execution.
-
- Precisely, which is why it is good to learn not to make redundant casts.
-
- If you don't put in casts, you will get warnings for any conversion not
- normally correct. This is helpful.
-
- -s
- --
- Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
- C/Unix wizard -- C/Unix questions? Send mail for help. No, really!
- FUCK the communications decency act. Goddamned government. [literally.]
- The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
-